import 'package:f_base_one/components/ProductItem.dart';
import 'package:f_base_one/model/Product.dart';
import 'package:flutter/material.dart';

class ProductList extends StatelessWidget {
  final List<Product> products;
  final Map<int, bool> selectedProducts;
  final Function(int, bool) onProductSelected;
  final Function(int, int) onUpdateProductQuantity;

  const ProductList({
    super.key,
    required this.products,
    required this.selectedProducts,
    required this.onProductSelected,
    required this.onUpdateProductQuantity,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children:
          products.map((product) {
            return ProductItem(
              key: ValueKey(product.id), // 使用 ValueKey 避免不必要的重建
              product: product,
              selectedProducts: selectedProducts,
              onSelected: (bool selected) {
                onProductSelected(product.id, selected);
              },
              onUpdateQuantity: (int quantity) {
                onUpdateProductQuantity(product.id, quantity);
              },
            );
          }).toList(),
    );
  }
}
